﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.Web;



namespace ParamiliarControls
{
    public partial class frmErrorHandler : Form
    {
        string errorReport = "";
        //httpPostData http = new httpPostData();
        httpPostData http = new httpPostData("http://test.candasys.co.uk/deployments/error_handler.php"); 
            
        public frmErrorHandler(Exception ex)
        {
            InitializeComponent();

            errorReport += "Error No. : " + ex.GetHashCode() + "\n";
            http.Add("error_no", ex.GetHashCode().ToString());

            errorReport += "Message: " + ex.Message + "\n";
            http.Add("message", ex.Message);

            lblDetails.Text = errorReport;

            errorReport += "Source: " + ex.Source + "\n";
            http.Add("source", ex.Source);
            errorReport += "Stack Trace: " + ex.StackTrace + "\n";
            http.Add("stack", ex.StackTrace);
            errorReport += "Target Site: " + ex.TargetSite + "\n";
            http.Add("targetsite", ex.TargetSite.ToString());
        }

        private void btnDetails_Click(object sender, EventArgs e)
        {
            if (panel1.Visible)
            {
                panel1.Visible = false;
                btnDetails.Text = "Details >>";
            }
            else
            {
                panel1.Visible = true;
                btnDetails.Text = "Details <<";
            }
            
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string resp = "";
            resp = http.GetResponse();

            //resp = http.senddata("http://test.candasys.co.uk/deployments/error_handler.php");
            //MessageBox.Show(resp);
            if (resp == "1")
            {
                MessageBox.Show("Thank you for submitting the error report.");
                btnSubmit.Visible = false;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
